﻿using System;
using NopSolutions.NopCommerce.Common.Utils;

namespace NopSolutions.NopCommerce.Web.Modules.Catalog
{
    public partial class ProductShare : BaseNopFrontendUserControl
    {
        protected override void OnPreRender(EventArgs e) {
            if (this.ProductService.ShowShare) {

                // facebook
                string shareFacebookCode = this.SettingManager.GetSettingValue("Products.Share.FacebookCode");
                if (CommonHelper.IsCurrentConnectionSecured()) {
                    //need to change the addthis link to be https linked when the page is, so that the page doesnt ask about mixed mode when viewed in https...
                    shareFacebookCode = shareFacebookCode.Replace("http://", "https://");
                }
                if (!string.IsNullOrWhiteSpace(shareFacebookCode))
                    litShareFacebook.Text = shareFacebookCode;
                else
                    litShareFacebook.Visible = false;

                // google +1
                string shareGoogleCode = this.SettingManager.GetSettingValue("Products.Share.GoogleCode");
                if (CommonHelper.IsCurrentConnectionSecured()) {
                    //need to change the addthis link to be https linked when the page is, so that the page doesnt ask about mixed mode when viewed in https...
                    shareGoogleCode = shareGoogleCode.Replace("http://", "https://");
                }
                if (!string.IsNullOrWhiteSpace(shareGoogleCode))
                    litShareGoogleChrome.Text = shareGoogleCode;
                else
                    litShareGoogleChrome.Visible = false;
            }
            else {
                this.Visible = false;
            }
            base.OnPreRender(e);
        }
    }
}